<template>
  <div class="container">
    <!-- 面包屑导航 -->
    <div class="breadcrumb">
          <navbar></navbar>
    </div>
    <!-- 面包屑导航 -->
    <div class="Box">
      <div class="table_tab">
        <div class="inquiry">
          <div class="headerbox">
            <div class="header">
              积分统计
            </div>

          </div>
          <div class="table">
           <matrix-table :dataList="commission.page.list" :config="commission.config"  ></matrix-table>
           </div>
        </div>
        <div class="inquiryTab">
          <div class="inquiryTab_header">
            <div class="tabTitle">积分查询</div>
          </div>
          <div class="table">
           <matrix-table :dataList="manage.page.list" :config="manage.config" @receiveData="handlerEmitFanStr"></matrix-table>
             <div class="page" >
               <div class="block">
                  <el-pagination
                      @size-change="onSizeChange"
                      @current-change="onCurrentChange"
                      :current-page="manage.page.pageNo"
                      :page-size="manage.page.pageSize"
                      :page-sizes="[3, 5, 10, 20, 50]"
                      layout="total, sizes,prev, pager, next"
                      :total="manage.page.totalNum">
                  </el-pagination>
                </div>
             </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import MatrixTable from './components/MatrixTable.vue'
import common from './mixins/common'
import navbar from '@/components/navbar.vue'
export default {
  mixins: [common],
  watch: {

  },
  components: {
    MatrixTable,
    navbar
  },
  data () {
    return {
      commission: {
        loading: false,
        page: { list: [], pageNo: 1, pageSize: 10, totalNum: 0, currentPage: 1 }, // 员工业绩统计(XX年XX月)
        sortObj: { prop: 'marketPrice', order: 'descending' }, // 排序
        config: [
          { prop: 'totalPoints', label: '积分总数' },
          { prop: 'usedPoints', label: '已使用' },
          { prop: 'balancePoints', label: '未使用' },
          { prop: 'receivedPoints', label: '已到账' },
          { prop: 'awaitPoints', label: '未到账' }
        ]
      },
      manage: {
        loading: false,
        page: { list: [], pageNo: 1, pageSize: 10, totalNum: 0, currentPage: 1 }, // 员工业绩统计(XX年XX月)
        sortObj: { prop: 'marketPrice', order: 'descending' }, // 排序
        config: [
          { prop: 'monthDate', label: '积分月份' },
          { prop: 'totalPoints', label: '积分总数' },
          { prop: 'usedPoints', label: '已使用' },
          { prop: 'balancePoints', label: '未使用' },
          { prop: 'receivedPoints', label: '已到账' },
          { prop: 'awaitPoints', label: '未到账' },
          { prop: 'updatedTime', label: '操作', slot: 'details' }
        ]
      },
      parArray: []
    }
  },
  mounted () {

  },
  created () {
    // this.fetchData()
    this.getStatisticsDataList()
    this.getDataList()
    // 权限设定判断
    this.limits = JSON.parse(sessionStorage.getItem('limit'))
    const params = this.limits.buttonTreeDto.filter(
      (item) => item.menuCode === 'categoryManage'// 菜单管理里面的菜单编码
    )
    params[0].buttonList.forEach((item) => {
      this.parArray.push(item.code)
    })
    console.log(this.parArray)
    // 权限设定判断
    document.onkeydown = (e) => {
      const key = window.event.keyCode
      if (key == 13) {
        this.searchEvent()
      }
    }
  },
  beforeRouteLeave (to, form, next) {
    document.onkeydown = null
    next()
  },

  methods: {
    getStatisticsDataList () {
      const params = {}
      this.$api.matrixStatiticsIntegral(params).then((res) => {
        if (res.code === 0) { this.commission.page.list.push(res.data) }
      }).catch((err) => {
        console.log(err)
      })
    },
    getDataList () {
      const data = {
        pageNo: this.manage.page.pageNo,
        pageSize: this.manage.page.pageSize
      }
      this.$api.matrixMonthPageListIntegral(data).then((res) => {
        console.log(res, 're')
        if (res.code === 0) {
          this.manage.page.list = res.data.list
          this.manage.page.totalNum = res.data.totalNum
        }
      }).catch((err) => {
        console.log(err)
      })
    },
    handlerEmitFanStr (e) {
      console.log(e)
      this.$router.push({ path: '/matrix/integralDetails', query: {
        monthDate: e.row.monthDate
      }})
    },
    onSizeChange (sizeChange) {
      this.manage.page.pageNo = 1
      this.manage.page.currentPage = 1
      this.manage.page.pageSize = sizeChange
      this.getDataList()
    },
    onCurrentChange (currentChange) {
      this.manage.page.pageNo = currentChange
      this.getDataList()
    },
    fetchData (type) {
      if (type === 'reset') {
        this.manage.page.pageNo = 1
        this.manage.page.pageSize = 10
        this.manage.page.currentPage = 1
      }
      let params = {
        pageNo: this.manage.page.pageNo,
        pageSize: this.manage.page.pageSize
      }
      if (type === 'search') {
        this.manage.page.currentPage = 1
        this.manage.page.pageNo = 1
        params.pageNo = 1
        params = Object.assign({}, params, this.search)
        // 去除字符串 前后 空格
        for (const item in params) { if (typeof params[item] === 'string') { params[item] = params[item].trim() } }
      }
      this.$api.goodsPageList(params).then((res) => {
        console.log(res)
        this.manage.page.list = res.data.list
        this.manage.page.totalNum = res.data.totalNum
      }).catch((err) => {
        console.log(err)
      })
    }
  }
}
</script>
<style scoped lang="scss">
.Box {
  display: flex;
  justify-content: flex-start;
  width: 100%;

  .table_tab {
    width: 100%;
    margin-bottom: 50px;
  }
}
.table {
  border-radius: 5px;
  width: 100%;
}

.header {
  display: flex;
  align-items: center;
  font-size: 18px;
  font-family: PingFang SC;
  font-weight: bold;
  color: #333333;
  padding-bottom: 10px;
}

.inquiry {
  background: #fff;
  padding: 10px 20px 10px 20px;
  border-radius: 5px;
  .el-form {
    margin-top: 10px;
  }
}
.inquiryTab {
  background: #fff;
  padding: 10px 20px 20px 20px;
  border-radius: 5px;
  .el-form {
    margin-top: 10px;
  }
  margin-top: 20px;
  .inquiryTab_header {
    display: flex;
    justify-content: space-between;
    /deep/ .el-button {
      height: 40px;
    }
  }
}

/deep/.el-table__expand-icon > .el-icon {
  color: transparent;
}

.table {
  margin-top: 10px;
  border: 1px solid #e8eaec;
  border-radius: 0;
  /deep/ .el-input--suffix .el-input__inner {
    color: #000;
    width: 104px;
    box-shadow: none;
  }
  /deep/ .el-button {
    padding: 10px 13px;
  }
}

.page {
  text-align: right;
  width: 100%;
  background: #f5f5f5;
  padding-right: 30px;
  position: fixed;
  bottom: 0px;
  right: 0px;
  z-index: 5;

  span {
    font-size: 14px;
    color: #666;
    display: inline-block;
    margin-left: 10px;
  }
  .el-pagination {
    display: inline-block;
    vertical-align: middle;
  }
}
/deep/.el-table__row:hover {
  color: rgb(45, 125, 223);
}
/deep/.el-dialog__header {
  padding: 20px 20px 20px 20px;
  font-family: PingFang SC;
  font-weight: bold;
  line-height: 25px;
  color: #333333;
}
/deep/.el-dialog {
  border-radius: 10px;
}
/deep/.el-dialog__headerbtn {
  top: 15px;
}
.headerbox {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
}

.tabTitle {
  font-size: 18px;
  font-family: PingFang SC;
  font-weight: 400;
  line-height: 25px;
  color: #333333;
  opacity: 1;
  margin-top: 10px;
  margin-bottom: 20px;
}
/deep/.el-form-item__label {
  font-size: 14px;
  font-family: PingFang SC;
  font-weight: 400;
  color: #333333;
}

/deep/ .el-dialog__footer {
  margin-top: -20px;
  padding-top: 20px;
}
/deep/.el-table thead {
  font-size: 16px;
  font-family: PingFang SC;
  font-weight: bold;
  line-height: 22px;
  color: #333333;
  opacity: 1;
}

.btnClass{
  margin-top: 20px;
  display: flex;
  justify-content: right;
}
 :deep(.avatar-uploader .el-upload ){
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 90px;
    height: 90px;
    line-height: 90px;
    text-align: center;
  }
  .avatar {
    width: 90px;
    height: 90px;
    display: block;
  }
</style>
